package com.byjh.app.mapper;

import java.util.List;

import com.byjh.app.domain.Question;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.cursor.Cursor;
import org.apache.ibatis.mapping.ResultSetType;

/**
 * 题目Mapper接口
 *
 * @author Dhq
 * @date 2025-01-15
 */
public interface QuestionMapper {
    /**
     * 查询题目
     *
     * @param id 题目主键
     * @return 题目
     */
    public Question selectQuestionById(Long id);

    /**
     * 查询易错误99题目列表
     *
     * @return 题目列表
     */
    List<Question> selectError99QuestionList();

    /**
     * 用户错题集
     * @param userId
     * @return
     */
    List<Question> selectErrorCollectSetQuestionList(@Param("userId") Long userId,@Param("chapterId") Long chapterId,@Param("type") Integer type);

    /**
     * 流式查询题目列表
     *
     * @return
     */

    @Select("select q.id, q.chapter_id, q.content, q.difficulty, q.`analyze`,q.score,c.`name` AS chapter_name from question AS q\n" +
            "LEFT JOIN chapter AS c ON c.id = q.chapter_id")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "chapterName", column = "chapter_name"),
            @Result(property = "chapterId", column = "chapter_id"),
            @Result(property = "content", column = "content"),
            @Result(property = "difficulty", column = "difficulty"),
            @Result(property = "analyze", column = "analyze"),
            @Result(property = "score", column = "score"),
    })
    @Options(resultSetType = ResultSetType.FORWARD_ONLY)
    Cursor<Question> selectQuestionListCursor();

    /**
     * 查询题目列表
     *
     * @param question 题目
     * @return 题目集合
     */
    public List<Question> selectQuestionList(Question question);

    /**
     * 新增题目
     *
     * @param question 题目
     * @return 结果
     */
    public int insertQuestion(Question question);

    /**
     * 修改题目
     *
     * @param question 题目
     * @return 结果
     */
    public int updateQuestion(Question question);

    /**
     * 更新错误次数
     */
    public int updateErrorCount(Long id);

    /**
     * 删除题目
     *
     * @param id 题目主键
     * @return 结果
     */
    public int deleteQuestionById(Long id);

    /**
     * 批量删除题目
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteQuestionByIds(Long[] ids);
}
